/*
 * @Author: dfh
 * @Date: 2024-03-13 14:22:50
 * @LastEditors: dfh
 * @Modified By: dfh
 * @describe: 
 */

const {
    miniProgram: { envVersion }
} = uni.getAccountInfoSync();


export function setToken(token) {
    uni.setStorageSync(`${envVersion}_token`, token);
}
export function getToken() {
    return uni.getStorageSync(`${envVersion}_token`);
}
export function _debounce(fn, wait, immediate = false) {
    let timer,
        startTimeStamp = 0,
        context,
        args;

    let run = (timerInterval) => {
        timer = setTimeout(() => {
            let now = new Date().getTime();
            let interval = now - startTimeStamp;
            if (interval < timerInterval) {
                startTimeStamp = now;
                run(wait - interval);
            } else {
                if (!immediate) {
                    fn.apply(context, args);
                }
                clearTimeout(timer);
                timer = null;
            }
        }, timerInterval);
    };

    return function () {
        context = this;
        args = arguments;
        let now = new Date().getTime();
        startTimeStamp = now;

        if (!timer) {
            if (immediate) {
                fn.apply(context, args);
            }
            run(wait);
        }
    };
}

export function validatePhoneNumber(phoneNumber) {
    if (!phoneNumber) return false;
    var regex = /^(\+?86|0)?1\d{10}$/;
    return regex.test(phoneNumber);
}

export function noUseingFn(){
    uni.showToast({
        title:'暂未开放',
        icon:'none'
    })
}
